package cn.itsource.org.service.impl;

import cn.itsource.basic.PageList;
import cn.itsource.org.domain.Department;
import cn.itsource.org.mapper.DepartMentMapper;
import cn.itsource.org.query.DepartMentQuery;
import cn.itsource.org.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartMentMapper departMentMapper;

    @Override
    public Department queryById(Long id) {
        return departMentMapper.selectById(id);
    }

    @Override
    @Transactional
    public void add(Department department) {
        departMentMapper.addDepaerMent(department);

    }

    @Override
    @Transactional
    public void delete(Long id) {
        departMentMapper.delete(id);

    }

    @Override
    @Transactional
    public void update(Department department) {
        departMentMapper.update(department);

    }

    @Override
    public List<Department> queryAll() {
        return departMentMapper.loadAll();
    }

    @Override
    public PageList<Department> pageLoad(DepartMentQuery query) {
        Long count = departMentMapper.count();
        List<Department> departments = departMentMapper.pageLoad(query);
        PageList<Department> lists = new PageList<>();
        lists.setRows(departments);
        lists.setTotal(count);
        return lists;
    }

}
